package com.qinhao.loveCrowdFunding.config;

import com.qinhao.loveCrowdFunding.handler.MyMessageHandler;
import com.qinhao.loveCrowdFunding.interceptor.WebSocketInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.EnableWebSocket;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;

@Configuration
@EnableWebSocket
public class WebSocketConfig implements WebSocketConfigurer {
    @Autowired
    MyMessageHandler myMessageHandler;
    // 注册handle
    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
        webSocketHandlerRegistry.addHandler(myMessageHandler, "/swapMessage").addInterceptors(new WebSocketInterceptor()).setAllowedOrigins("*");
        webSocketHandlerRegistry.addHandler(myMessageHandler, "/socketJs/swapMessage").addInterceptors(new WebSocketInterceptor()).setAllowedOrigins("*").withSockJS();
    }
}
